
package load.logic;

import core.DispatcherPort;
import core.InPort;
import core.StdNode;
import core.TriggerPort;

/**
 * Node which behaves like "if(cond) thenPort else elsePort".
 * When 'execute' is triggered, 'thenPort' is triggered if the value
 * of 'condition' is true, otherwise 'elsePort' is triggered.
 * 
 * @author Wijnand
 */
public class If extends StdNode {
	private DispatcherPort thenPort = new DispatcherPort();
	private DispatcherPort elsePort = new DispatcherPort();
	private DispatcherPort conditionChanged = new DispatcherPort();
	
	private InPort condition = new InPort(Boolean.class);
	
	private TriggerPort execute = new TriggerPort() {
		@Override
		public void callInternal() {
			if (((Boolean)condition.getValue()).booleanValue())
				thenPort.callTargets();
			else
				elsePort.callTargets();
		}
	};
	
	public If() {
		autoPutPorts();
	}
}
